﻿/******************************************************************
** 文 件 名: Bu_DocReceive_Temp_List.aspx.cs
** Copyright (c) 2010-2012 Honestysoft (GuangZhou) Co.,LTD
** 创 建 人: 此代码由生成器自动生成
** 创建日期: 2012-4-14 15:23:08
** 描    述: 资料接收表回执--首次新增列表页面
** 版    本: 2.0.0.0
** 修改描述:
** 修 改 人:
** 修改日期:
******************************************************************/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Text;
using Honestysoft.BaseLibrary;
using Honestysoft.BaseObject;
using Honestysoft.BaseLibrary.ExceptionHandling;
using Honestysoft.Baseframework.WebUI;
using Honestysoft.Financing.Model;
using System.Data.Common;

namespace Honestysoft.Financing.WebUI.Module.Audit
{
	public partial class Bu_DocReceive_Temp_List : BasePage
	{	
		protected override void Page_Load(object sender, EventArgs e)
        {
			base.Page_Load(sender, e);
            if (!IsPostBack)
            {		
				AspNetPager1.PageSize = Globals.PageSize;
				BindControl();
                Bind();
            }
        }
		/// <summary>
        /// 绑定页面控件。
        /// </summary>
		private void BindControl()
		{
            //ControlHelper.BindEnum(ddlDocRecieveStatus, "DocRecieveStatus");//请修改成typeof(EnumItem.XXX)
            //ControlHelper.InsertAllItemAndSelect(ref ddlDocRecieveStatus);
		}
		/// <summary>
        /// 设置弹出窗体大小
		/// 基类中已自动做控制。默认宽度800，高度600
        /// </summary>
		protected override void SetDialogSize()
		{
			base.SetDialogSize();
			//重载宽度，高度
			//ModalDialogSize.EditHeight =250;
            //ModalDialogSize.EditWidth = 500;
            //ModalDialogSize.ViewHeight = 250;
            //ModalDialogSize.ViewWidth = 500;
		}
		/// <summary>
        /// 根据权限控制页面按钮.
        /// 基类中已自动做控制。
        /// </summary>
        protected override void ButtonSetting()
        {
            base.ButtonSetting();
            //使用PageSecurity检查权限
            if (PageSecurity.Add)
            {
                btnProjAdd.Attributes.Add("onclick", "javascript:openDialog('" + Globals.Home + "Module/Audit/FirstProjDocReceive_Edit.aspx?IsNew=1&FunctionID=" + FunctionID + "'," + ModalDialogSize.EditWidth + ", " + ModalDialogSize.EditHeight + ", '新增资料接收表(回执)');return false;");
                btnConAdd.Attributes.Add("onclick", "javascript:openDialog('" + Globals.Home + "Module/Audit/FirstConDocReceive_Edit.aspx?IsNew=1&FunctionID=" + FunctionID + "'," + ModalDialogSize.EditWidth + ", " + ModalDialogSize.EditHeight + ", '新增资料接收表(回执)');return false;");
            }
        }
		/// <summary>
        /// 得到查询参数
        /// </summary>
        /// <returns>查询参数</returns>
		private QueryParameters GetQueryParameters()
		{
			QueryParameters queryParameters = new QueryParameters();
			if(txtProjectName.Text.Trim().Length > 0)
			{
				queryParameters.Add("ProjectName",txtProjectName.Text,QueryParameters.OperatorType.Like);
			}
			if(txtContractName.Text.Trim().Length > 0)
			{
				queryParameters.Add("ContractName",txtContractName.Text,QueryParameters.OperatorType.Like);
			}
			return queryParameters;
		}
		/// <summary>
        /// 得到排序参数
        /// </summary>
        /// <returns></returns>
		private OrderParameters GetOrderParameters()
		{
			OrderParameters orderParameters = new OrderParameters();
			//添加排序列
            orderParameters.Add("Code", OrderParameters.OrderDirection.Desc);
			return orderParameters;
		}

        protected string GetNewType(bool isProjectFirst)
        {
            if (isProjectFirst) { return "项目首次申请"; }
            return "合同首次申请"; 
        }

        //private List<Bu_BatchRec> mBatchRec = null;

		/// <summary>
        /// 绑定列表
        /// </summary>
		private void Bind()
        {
			QueryParameters queryParameters = GetQueryParameters();
			OrderParameters orderParameters = GetOrderParameters();
			BaseBusinessLogic<Bu_DocReceive_Temp> baseLogic = new BaseBusinessLogic<Bu_DocReceive_Temp>();
            int pageCount = 0, recordCount = 0;
            DataTable dtList = baseLogic.GetTablePaging(queryParameters, orderParameters, AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, out pageCount, out recordCount);
            AspNetPager1.RecordCount = recordCount;
            rptList.DataSource = dtList;
            //List<string> lsRecID = new List<string>();
            //foreach (DataRow dr in dtList.Rows)
            //{
            //    lsRecID.Add(dr["ID"].ToString());
            //}
            //QueryParameters query = new QueryParameters();
            //query.Add("RecID",lsRecID, QueryParameters.OperatorType.IN);
            //mBatchRec = new Honestysoft.BaseObject.BaseBusinessLogic<Bu_BatchRec>(Globals.CurrentConnStringName).GetEntitys(query);
            rptList.DataBind();
        }
		/// <summary>
        /// 得到表格行操作按钮脚本
        /// </summary>
        /// <param name="dataId">记录ID</param>
        /// <param name="isProjectNew">是否项目首次</param>
        /// <param name="isToDatabase">是否已入库</param>
        /// <returns>操作按钮脚本</returns>
        protected string GetButtonScript(string dataId,bool isProjectNew, bool isToDBProj,bool isToDBCon)
        {
            string script = "";
            //如果是新增项目，必须先入项目，再入合同
            if (isProjectNew)
            {
                if (isToDBCon && isToDBProj)
                {
                    script += ScriptHelper.LinkButton.GetGridViewButton(Globals.Home + "Module/Audit/DocReceivePrint.aspx", "查看资料接收表(回执)", ModalDialogSize.ViewWidth, ModalDialogSize.ViewHeight, dataId, FunctionID, "&IsNew=0&IsUse=1", "", "", "");
                }
                else
                {
                    script += ScriptHelper.LinkButton.GetGridViewButton(Globals.Home + "Module/Audit/DocReceivePrint2.aspx", "查看资料接收表(回执)", ModalDialogSize.ViewWidth, ModalDialogSize.ViewHeight, dataId, FunctionID, "&IsNew=0&IsProjectFirst="+(isProjectNew ? "1" : "0"), "", "", "");
                    if (!isToDBProj)
                    {
                        script += "&nbsp;&nbsp;";
                        script += ScriptHelper.LinkButton.GetGridImageButton("doToDatabaseProject('" + dataId + "','" + UserLoginer.LoginUser.ID + "')", "../../images/database_copy.png", "将首次申请的项目资料纳入系统数据库！", "");
                    }                    
                    if (!isToDBCon)
                    {
                        script += "&nbsp;&nbsp;";
                        if (isToDBProj)
                        {
                            script += ScriptHelper.LinkButton.GetGridImageButton("doToDatabaseContract('" + dataId + "','" + UserLoginer.LoginUser.ID + "')", "../../images/database_table.png", "将首次申请的合同资料纳入系统数据库！", "");
                        }
                        else
                        {
                            script += ScriptHelper.LinkButton.GetGridImageButton("alert('项目未入库，必须先将项目入库再执行合同入库操作！');return;", "../../images/database_table.png", "将首次申请的合同资料纳入系统数据库！", "");
                        }
                    }
                }
            }
            else
            {
                if (!isToDBCon)
                {
                    script += ScriptHelper.LinkButton.GetGridImageButton("doToDatabaseContract('" + dataId + "','" + UserLoginer.LoginUser.ID + "')", "../../images/database_copy.png", "将首次申请的合同资料纳入系统数据库！", "");
                    script += "&nbsp;&nbsp;"+ ScriptHelper.LinkButton.GetGridViewButton(Globals.Home + "Module/Audit/DocReceivePrint2.aspx", "查看资料接收表(回执)", ModalDialogSize.ViewWidth, ModalDialogSize.ViewHeight, dataId, FunctionID, "&IsNew=0&IsProjectFirst=" + (isProjectNew ? "1" : "0"), "", "", "");
                }
                else
                {
                    script += ScriptHelper.LinkButton.GetGridViewButton(Globals.Home + "Module/Audit/DocReceivePrint.aspx", "查看资料接收表(回执)", ModalDialogSize.ViewWidth, ModalDialogSize.ViewHeight, dataId, FunctionID, "&IsNew=0&IsUse=1", "", "", "");
                }
            }
            return script;
        }
		
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            Bind();
        }
		
		protected void btnQuery_Click(object sender, EventArgs e)
        {
            Bind();
        }
		/// <summary>
        /// 得到选中的记录ID集合
        /// </summary>
        /// <returns></returns>
        private string[] GetSelectedRowKeys()
        {
            string strId = Request["chkID"]+"";
            if (string.IsNullOrEmpty(strId)) { return null; }
            return strId.Split(',');
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            DbTransaction transaction = Honestysoft.BaseLibrary.Data.DatabaseProvider.GetDbTransaction(Globals.CurrentConnStringName);
            DbConnection connection = transaction.Connection;
            try
            {
                string[] arrId = GetSelectedRowKeys();
                List<string> lsID = new List<string>();
                lsID.AddRange(arrId);
                new Honestysoft.Workflow.BusinessFacade.WFApply.FlowManage(Globals.CurrentConnStringName).DeleteWorkflow(((int)EnumItem.WFBill.AuditTable).ToString(), lsID, transaction);
                new Honestysoft.Financing.BusinessLogic.Audit(Globals.CurrentConnStringName).DeleteDocReceiveTemp(arrId, transaction);
                transaction.Commit();
                ScriptHelper.Window.Alert("删除成功！");
                Bind();
            }
            catch (Honestysoft.BaseLibrary.ExceptionHandling.BaseException bex)
            {
                transaction.Rollback();
                ExceptionHelper.ExceptionDistribute(bex, false);
                ScriptHelper.Window.Alert(bex.Message);
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                ExceptionHelper.ExceptionDistribute(ex, false);
                ScriptHelper.Window.Alert("删除失败！系统发生了未知错误！");
            }
            finally
            {
                connection.Close();
            }
        }
	}
}
